//
//  StaffHomeViewController.m
//  AppHelpStaff
//
//  Created by Zheng on 2018/7/10.
//  Copyright © 2018年 app.help.staff.zhengcx. All rights reserved.
//

#import "StaffHomeViewController.h"
#import "StaffBaseYellowTitleView.h"
#import "StaffBaseTableViewCell.h"
#import "StaffHomeListCell.h"

@interface StaffHomeViewController () <SDCycleScrollViewDelegate>

@property (nonatomic, strong) SDCycleScrollView *cycleScrollView;


@end

@implementation StaffHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self registerCell];
}

#pragma mark - Subviews
#pragma amrk layout subviews
- (void)layoutSubviewsInView {
    [super layoutSubviewsInView];
}

#pragma mark create subviews
- (void)createSubviews {
    [super createSubviews];
    
    self.tableView.tableHeaderView = self.cycleScrollView;

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"search"] style:UIBarButtonItemStyleDone target:self action:@selector(searchItemAction)];
    
}

- (SDCycleScrollView *)cycleScrollView {
    if (!_cycleScrollView) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenWidth, kScale(150)) delegate:self placeholderImage:nil];
        _cycleScrollView.backgroundColor = kRGB(255, 255, 255, 1);
        _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
        _cycleScrollView.autoScrollTimeInterval = 3;
        _cycleScrollView.imageURLStringsGroup = @[@"http://img.zcool.cn/community/01c48e56d3a48232f875520fe5f4a1.jpg",
                                                  @"http://img.zcool.cn/community/01c48e56d3a48232f875520fe5f4a1.jpg",
                                                  @"http://img.zcool.cn/community/01c48e56d3a48232f875520fe5f4a1.jpg",
                                                  @"http://img.zcool.cn/community/01c48e56d3a48232f875520fe5f4a1.jpg"];
    }
    return _cycleScrollView;
}

#pragma mark - register cell
- (void)registerCell {
    
    [self.tableView registerClass:[StaffBaseTableViewCell class] forCellReuseIdentifier:@"quickCellID"];
    [self.tableView registerClass:[StaffHomeListCell class] forCellReuseIdentifier:@"listCellID"];
}

#pragma mark - tableview datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        StaffBaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"quickCellID" forIndexPath:indexPath];
        cell.bgImgv.image = [UIImage imageNamed:@"home_rapid_bg"];
        return cell;
    } else {
        StaffHomeListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"listCellID" forIndexPath:indexPath];
        return cell;
    }
}

#pragma mark - tableview delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kScale(110);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return kScale(45);
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *headerView = [[UIView alloc] init];
    
    headerView.frame = CGRectMake(0, 0, kScreenWidth, kScale(45));
    NSString *title = section == 0 ? @"快速匹配": @"匹配推荐";
    StaffBaseYellowTitleView *titleView = [[StaffBaseYellowTitleView alloc] initWithTitle:title];
    titleView.frame = CGRectMake(kScale(30), kScale(15), kScale(75), kScale(15));
    [headerView addSubview:titleView];
    return headerView;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        NSLog(@"点击了快速匹配");
    } else {
        NSLog(@"点击了%ld",indexPath.row);
    }
}


#pragma markr - 点击事件
- (void)searchItemAction {
    NSLog(@"点击了搜索按钮");
}

@end
